/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Modellayer;
import java.util.ArrayList;
import java.io.*;

/**
 *
 * @author Søren
 */
public class SalesOrderCollection implements Serializable{


    private ArrayList<SalesOrder> OrderList;
    private static SalesOrderCollection instance = new SalesOrderCollection();



    public SalesOrderCollection()
    {
        OrderList = new ArrayList<SalesOrder>();
    }

    public static SalesOrderCollection getInstance()
    {
    	return instance;
    }

    public void addOrder(SalesOrder order)
    {
	OrderList.add(order);
    }

    public int getSize()
    {
    	return OrderList.size();
    }

    public SalesOrder getOrderByID(int salesOrderID)
	{
		//denne metode finder en specimen ud fra serie nummeret (serialNr)
		int i = 0;
		boolean found = false;

		while(i < OrderList.size() && !found)
		{
			if(OrderList.get(i).getSalesOrderID() == salesOrderID)
			{
				found = true;
			}
			else
			{
				i++;
			}
		}

		if(found)
		{
			return OrderList.get(i);
		}
		else
		{
			return null;
		}
	}


    public void removeSalesOrderByID(int salesOrderID)
	{
		//denne metode sletter en metode via Serie nummeret (serialNr)
		int i = 0;
		boolean found = false;
		int isaver = 0;
		while(i < OrderList.size() && !found)
		{
			if(OrderList.get(i).getSalesOrderID() == salesOrderID)
			{
				isaver = i;
				found = true;
			}
			i++;
		}

		if(found)
		{
			OrderList.remove(isaver);
		}
	}

}
